<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="采购方总部编码" prop="purchaserHqCode">
                <el-input v-model="queryParams.purchaserHqCode" placeholder="请输入采购方总部编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="生产订单编号" prop="ipoNo">
                <el-input v-model="queryParams.ipoNo" placeholder="请输入供应商生产订单编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <!--<el-form-item label="供应商编码" prop="supplierCode">
                <el-input v-model="queryParams.supplierCode" placeholder="请输入供应商编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="供应商名称" prop="supplierName">
                <el-input v-model="queryParams.supplierName" placeholder="请输入供应商名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>-->
            <el-form-item label="生产工单编码" prop="woNo">
                <el-input v-model="queryParams.woNo" placeholder="请输入生产工单编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="品类编码" prop="categoryCode">
                <el-input v-model="queryParams.categoryCode" placeholder="请输入品类编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          <!--<el-form-item label="种类编码" prop="subclassCode">
              <el-input v-model="queryParams.subclassCode" placeholder="请输入种类编码"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="厂家物料编码" prop="materialsCode">
              <el-input v-model="queryParams.materialsCode" placeholder="请输入厂家物料编码"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="厂家物料描述" prop="materialsDescription">
              <el-input v-model="queryParams.materialsDescription" placeholder="请输入厂家物料描述"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="物料批次" prop="materialsBatch">
              <el-input v-model="queryParams.materialsBatch" placeholder="请输入物料批次"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="生产数量" prop="amount">
              <el-input v-model="queryParams.amount" placeholder="请输入生产数量"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="计量单位" prop="unit">
              <el-input v-model="queryParams.unit" placeholder="请输入计量单位"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="计划开始日期" prop="planStartDate">
              <el-input v-model="queryParams.planStartDate" placeholder="请输入计划开始日期"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="计划完成日期" prop="planFinishDate">
              <el-input v-model="queryParams.planFinishDate" placeholder="请输入计划完成日期"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="实际开始日期" prop="actualStartDate">
              <el-input v-model="queryParams.actualStartDate" placeholder="请输入实际开始日期"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="实际完成日期" prop="actualFinishDate">
              <el-input v-model="queryParams.actualFinishDate" placeholder="请输入实际完成日期"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="工艺路线编码" prop="processRouteNo">
              <el-input v-model="queryParams.processRouteNo" placeholder="请输入工艺路线编码"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="电压等级" prop="voltageLevel">
              <el-input v-model="queryParams.voltageLevel" placeholder="请输入电压等级"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="产品型号规格" prop="modelSpec">
              <el-input v-model="queryParams.modelSpec" placeholder="请输入产品型号规格"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="子种类编号" prop="subcategoryCode">
              <el-input v-model="queryParams.subcategoryCode" placeholder="请输入子种类编号"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="物资子种类" prop="subcategoryName">
              <el-input v-model="queryParams.subcategoryName" placeholder="请输入物资子种类"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="产品名称" prop="productName">
              <el-input v-model="queryParams.productName" placeholder="请输入产品名称"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="电抗率" prop="reactanceRatio">
              <el-input v-model="queryParams.reactanceRatio" placeholder="请输入电抗率"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>-->
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                         v-hasPermi="['develop:FactoryProduceWork:add']">新增</el-button>
            </el-form-item>
        </el-form>

        <!--<el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                        v-hasPermi="['develop:FactoryProduceWork:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                        @click="handleUpdate" v-hasPermi="['develop:FactoryProduceWork:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                    <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                               v-hasPermi="['develop:FactoryProduceWork:remove']">删除</el-button>
                </el-popconfirm>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini"
                        @click="handleExport" v-hasPermi="['develop:FactoryProduceWork:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>-->

        <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="采购方总部编码" width="150" align="center" prop="purchaserHqCode"/>
            <el-table-column label="生产订单编号" width="150" align="center" prop="ipoNo"/>
            <!--<el-table-column label="供应商编码" align="center" prop="supplierCode"/>
            <el-table-column label="供应商名称" align="center" prop="supplierName"/>-->
            <el-table-column label="生产工单编码" width="150" align="center" prop="woNo"/>
            <el-table-column label="品类编码" width="150" align="center" prop="categoryCode"/>
            <el-table-column label="种类编码" width="150" align="center" prop="subclassCode"/>
            <el-table-column label="厂家物料编码" width="150" align="center" prop="materialsCode"/>
            <el-table-column label="厂家物料描述" width="150" align="center" prop="materialsDescription"/>
            <el-table-column label="物料批次" width="150" align="center" prop="materialsBatch"/>
            <el-table-column label="生产数量" width="150" align="center" prop="amount"/>
            <el-table-column label="计量单位" width="150" align="center" prop="unit"/>
            <el-table-column label="计划开始日期" width="150" align="center" prop="planStartDate"/>
            <el-table-column label="计划完成日期" width="150" align="center" prop="planFinishDate"/>
            <el-table-column label="实际开始日期" width="150" align="center" prop="actualStartDate"/>
            <el-table-column label="实际完成日期" width="150" align="center" prop="actualFinishDate"/>
            <el-table-column label="工单状态" width="150" align="center" prop="woStatus"/>
            <!--<el-table-column label="实物ID" align="center" prop="entityCode"/>-->
            <el-table-column label="工艺路线编码"  width="150"align="center" prop="processRouteNo"/>
            <el-table-column label="电压等级" width="150" align="center" prop="voltageLevel"/>
            <!--<el-table-column label="数据来源" align="center" prop="dataSource"/>
            <el-table-column label="来源数据创建时间" align="center" prop="dataSourceCreateTime"/>
            <el-table-column label="数据拥有方" align="center" prop="ownerId"/>
            <el-table-column label="数据可见方" align="center" prop="openId"/>-->
            <el-table-column label="产品型号规格" width="150" align="center" prop="modelSpec"/>
            <el-table-column label="子种类编号" width="150" align="center" prop="subcategoryCode"/>
            <el-table-column label="物资子种类" width="150" align="center" prop="subcategoryName"/>
            <el-table-column label="产品名称" width="150" align="center" prop="productName"  show-overflow-tooltip/>
            <el-table-column label="电抗率" width="150" align="center" prop="reactanceRatio"/>
            <el-table-column label="状态" width="150" align="center" prop="status"/>
            <el-table-column label="备注" width="300" align="center" prop="remark"/>
            <el-table-column label="操作" align="center" width="150" fixed="right" class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                      <el-button size="mini" type="text" icon="el-icon-edit"
                              @click="handleUpdate(scope.row)" v-hasPermi="['develop:FactoryProduceWork:edit']">修改</el-button>
                      <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                                     style="margin-left: 10px;">
                          <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                     v-hasPermi="['develop:FactoryProduceWork:remove']">删除</el-button>
                      </el-popconfirm>
                  </template>
              </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

        <factoryProduceWork-form ref="form" @ok="getList"></factoryProduceWork-form>
    </div>
</template>

<script>
    import { deleteAction, getAction } from '@/api/manage'
    import FactoryProduceWorkForm from '@/views/develop/factory/factoryProduceWork/module/FactoryProduceWorkForm'

    export default {
        name: "FactoryProduceWorkList",
        components: {
            FactoryProduceWorkForm,
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 工单信息表格数据
                dataList: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
            status: null,
            purchaserHqCode: null,
            ipoNo: null,
            supplierCode: null,
            supplierName: null,
            woNo: null,
            categoryCode: "60",
            subclassCode: "60004",
            materialsCode: null,
            materialsDescription: null,
            materialsBatch: null,
            amount: null,
            unit: null,
            planStartDate: null,
            planFinishDate: null,
            actualStartDate: null,
            actualFinishDate: null,
            woStatus: null,
            entityCode: null,
            processRouteNo: null,
            voltageLevel: null,
            dataSource: null,
            dataSourceCreateTime: null,
            ownerId: null,
            openId: null,
            modelSpec: null,
            subcategoryCode: null,
            subcategoryName: null,
            productName: null,
            reactanceRatio: null
                },
                url: {
                    list:'/factoryProduceWork/factoryProduceWork/list',
                    remove:'/factoryProduceWork/factoryProduceWork/',
                    export:'/factoryProduceWork/factoryProduceWork/export',
                },
                tableMaxHeight: window.innerHeight - 320,
            };
        },
        created() {
            this.getList();
            window.addEventListener('resize', this.getTableHeight);
        },
        destroyed () {
            window.removeEventListener('resize', this.getTableHeight)
        },
        methods: {
            /** 查询工单信息列表 */
            getList() {
                this.loading = true;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.dataList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            getTableHeight () {
                this.tableHeight = window.innerHeight - 320
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.$refs.form.handleAdd();
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.$refs.form.handleUpdate(row);
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                deleteAction(this.url.remove, ids).then(response => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
            /** 导出按钮操作 */
            handleExport() {
                this.download(this.url.export, {
                    ...this.queryParams
                }, `factoryProduceWork_${new Date().getTime()}.xlsx`)
            },
  }
};
</script>
